package com.jm.programming.stream;

import com.jm.programming.stream.pojo.Author;
import com.jm.programming.stream.utils.CreateDataUtil;

import java.util.*;
import java.util.stream.Stream;

/**
 * @Description
 * @date 2022/7/6 8:52
 */
public class CreateStreamTest {

    /**
     * 单列集合创建流
     * @return Stream
     */
    static Stream<Integer> singleColl(){

        List<Integer> list = new ArrayList<>();
        list.add(1);

        Set<Integer> set = new LinkedHashSet<>();
        set.add(1);

        return (Math.random() * 10) % 2 == 0 ? list.stream() : set.stream();
    }

    /**
     * 数组创建流对象
     * @return Stream
     */
    static Stream<Integer> ArrColl(){
        Integer[] arr = {1,2,3,4};
        return (Math.random() * 10) % 2 == 0 ? Arrays.stream(arr) : Stream.of(arr);
    }

    /**
     * 多列集合创建流对象
     */
    static void doubleColl(){
        Map<String , Integer> map = new HashMap<>();
        map.put("a",1);
        map.put("b",2);
        map.put("c",3);

        // 转成单行集合再转成stream
        Stream<Map.Entry<String, Integer>> stream = map.entrySet().stream();
    }



}
